﻿using System;
using System.Web;
using Dos.Model;

public partial class webmx_program_gongde_Set : PageBase
{
    public temple_Contents data;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(Request["id"]))
            AlertRedirect("参数错误，请重新打开。", "list.aspx");
        else
        {
            int id = int.Parse(Request["id"]);
            data = DB.Context.From<temple_Contents>().Select(s => new { s.ID, s.Title, s.Depict, s.Info, s.Photo, s.Attachment, s.CategoryID, s.Flag, s.SortID, s.AddTime }).Where(w => w.ID == id).First();
            if (IsPostBack)
            {
                if (IsPostBack)
                {
                    string imgname;
                    HttpPostedFile imgFile = HttpContext.Current.Request.Files[0];
                    if (imgFile != null && imgFile.ContentLength > 0)
                    {
                        imgname = Guid.NewGuid().ToString() + "." + imgFile.FileName.Split('.')[1];
                        string savePath = Server.MapPath("~/upload/gd/" + imgname);
                        imgFile.SaveAs(savePath);
                        data.Photo = imgname;
                    }
                    data.Title = Request.Form["txtname"].ToString();
                    data.Attachment = Request.Form["txtprice"].ToString();
                    data.SortID = int.Parse(Request.Form["txtsort"].ToString());
                    data.AddUser = (int)Session["manage"];
                    int res = DB.Context.Update(data);
                    if (res > 0)
                        AlertRedirect("更新成功!", "set.aspx?id=" + Request.QueryString["id"]);
                    else
                        Alert("更新失败，请重试!");
                }
            }
        }
    }
}